Skip to content

feat(classes): add cryptographic primitives#6

Closed
SamuelSchlesinger wants to merge 1 commit into
devfrom
feat/crypto-primitives
Closed

feat(classes): add cryptographic primitives#6
SamuelSchlesinger wants to merge 1 commit into
devfrom
feat/crypto-primitives

Conversation

@SamuelSchlesinger

Copy link
Copy Markdown
Owner

Summary

  • BitEncodable: Specification-level typeclass for encoding types as bit strings (List Bool). Instances for Unit, List Bool, Option (List Bool), and Prod. Used to state that a TM's bit-string I/O corresponds to a Lean function on abstract types — carries no computational obligation.
  • unpair: Left inverse of pair with roundtrip proof unpair (pair x y) = (x, y). Returns ([], []) for strings not in the image of pair.
  • PPTComputable: Predicate asserting a randomized function List Bool → PMF (List Bool) is computable by a PPT NTM, bridging NTM output distributions (outputCount) to Mathlib's PMF via ENNReal.
  • Made pair_nil_eq and pair_cons_eq public @[simp] lemmas (needed by unpair_pair).

Motivation

These are foundational building blocks for formalizing computational cryptography (KL Chapter 3). The cryptolib project will use BitEncodable and PPTComputable to define encryption schemes where algorithms are Lean functions with PPT realizability asserted via existential TM witnesses.

Test plan

  • lake build passes with no new errors or warnings

…TComputable)

Add foundational infrastructure for cryptographic formalization:

- BitEncodable: specification-level typeclass for encoding types as
  bit strings, with instances for Unit, List Bool, Option, and Prod.
- unpair: left inverse of pair, with roundtrip proof.
- PPTComputable: predicate asserting a randomized function
  (List Bool → PMF (List Bool)) is computable by a PPT NTM, bridging
  NTM output distributions to Mathlib's PMF via ENNReal.
- Make pair_nil_eq and pair_cons_eq public @[simp] lemmas.
| none => [false]
| some x => true :: x
decode
| [] => none

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this case?

Comment thread Complexitylib/Classes/BitEncodable.lean
Comment thread Complexitylib/Classes/BitEncodable.lean
@@ -17,14 +17,38 @@ search-problem classes.
def pair (x y : List Bool) : List Bool :=

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow why you need pair/unpair, rather than defining BitEncodable on products of bitstrings

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair.


## Main definitions

- `PPTComputable` — a randomized function is PPT-computable if there exists a PPT NTM

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "TM" not "NTM"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way we define PTMs here is as NTMs with certain properties. That said, maybe we should change the PTM definition to be a PTM which gets spawned with a worktape with a bunch of random bits on it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think defining a PTM as an NTM is non-standard; defining it as a TM with an extra random tape is better.

open Complexity

/-- A randomized function `f : List Bool → PMF (List Bool)` is **PPT-computable**
if there exists a PPT NTM whose output distribution matches `f` on all inputs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer.

and outputs `y`. The time bound `T` must be polynomial: `T =O (· ^ d)`
for some degree `d`. -/
def PPTComputable (f : List Bool → PMF (List Bool)) : Prop :=
∃ (k : ℕ) (tm : NTM k) (T : ℕ → ℕ) (d : ℕ),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure how you define NTM k with time bound T. Do you require that it consume a random tape of length exactly T?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noncomputable def acceptProb (tm : NTM n) (x : List Bool) (T : ℕ) : ℚ :=
might give you an idea of what's going on.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you re-define PTMs then I guess this will also change,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants